<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" name="referrer" content="no-referrer">
    <title>首页</title>
    <!-- 引入axios -->
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    <!-- 引入Vue -->
    <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
    <!-- import Element UI -->
    <script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <link rel="stylesheet" href="css/index.css">
</head>
<body>
<div id="app">
    <el-container>
        <el-header height="150px">
            <div style="width: 1400px;margin: 0 auto">
                <img src="../imgs/logo.png" width="300px">
                <a href="index.html">首页</a>
                <el-divider direction="vertical"></el-divider>
                <a href="#">热点资讯</a>
                <el-divider direction="vertical"></el-divider>
                <a href="https://zhaopin.meituan.com/web/social">社会招聘</a>
                <el-divider direction="vertical"></el-divider>
                <a href="https://zhaopin.meituan.com/web/campus">校园招聘</a>
                <el-divider direction="vertical"></el-divider>
                <a href="#">帮助</a>
                <el-divider direction="vertical"></el-divider>
                <span style="float: right;font-size: 15px;margin-top: 35px">
                    欢迎回来<a href="JavaScript:void(0)" style="text-decoration: none"
                               @click="myself">{{nickname}}</a>
                    &nbsp&nbsp&nbsp
                    <a href="JavaScript:void(0)" style="text-decoration: none" @click="logout">退出登录</a>
                </span>
            </div>
            <div style="background-color: #0aa1ed;border-radius: 10px">
                <el-menu style="width: 1400px ;margin: 0 auto" mode="horizontal"
                         background-color="#0aa1ed" text-color="#fff" active-text-color="#0f0"
                         @select="handleSelect">
                    <el-menu-item v-for="c in carousel" :index="c.id">{{c.name}}</el-menu-item>
                    <div style="float:right;position: relative;top:10px;right: 20px">
                        <el-input v-model="keyword" placeholder="请输入搜索内容">
                            <!--  slot="append" 设置按钮嵌入到文本框里面 -->
                            <el-button slot="append" @click="search" icon="el-icon-search"></el-button>
                        </el-input>
                    </div>
                </el-menu>
            </div>
        </el-header>
        <el-main>
            <el-row gutter="20">
                <el-col span="18">
                    <el-carousel :intercval="3000" type="card" height="445px">
                        <!--走马灯开始-->
                        <el-carousel-item v-for="b in bannerArr">
                            <img :src="b.url" width="100%" height="100%" v-if="b.enable===1">
                        </el-carousel-item>
                        <!-- 走马灯结束-->
                    </el-carousel>
                </el-col>
                <el-col span="6">
                    <el-card>
                        <h3>
                            <i class="el-icon-item"
                               style="font-family: 楷体">销量最高</i>
                        </h3>
                        <el-divider></el-divider>
                        <el-table :data="sales">
                            <el-table-column type="index" label="排名"></el-table-column>
                            <el-table-column prop="title" label="名称"
                                             :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column prop="sale" label="销量"></el-table-column>
                        </el-table>
                    </el-card>
                </el-col>
            </el-row>
            <el-row gutter="20">
                <el-col span="6" style="margin: 10px 0" v-for="g in goodsArr">
                    <el-card>
                        <a :href="'/user/detail.html?id='+ g.id">
                            <img :src="g.img" width="100%">
                        </a>
                        <p style="font-size: 14px">
                            <a :href="'/user/detail.html?id='+g.id" style="text-decoration: none;color: #666666">
                                {{g.title}}
                            </a>
                        </p>
                        <p style="font-size: 12px">
                            现价:{{g.price}} 原价:<s>{{g.oldPrice}}</s>
                        </p>
                    </el-card>
                </el-col>
            </el-row>
        </el-main>
        <el-footer>
            <div style="background-image:url('../imgs/wave.png'); height:95px"></div>
        </el-footer>
    </el-container>
</div>
</body>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                nickname: localStorage.getItem("nickname"),
                carousel: [],
                bannerArr: [],
                goodsArr: [],
                sales: [],
                cartCount: '',
                keyword: ''
            }
        },
        methods: {
            handleSelect(key, keyPath) {
                location.href = '/user/result.html?carouselId=' + key;
            },
            handleOpen(key, keyPath) {
                console.log('key = ' + key, 'leyPath = ' + keyPath);
            },
            handleClose(key, keyPath) {
                console.log('key = ' + key, 'leyPath = ' + keyPath);
            },

            myself() {
                console.log("即将进入我的中心")
                location.href = '/user/Myself.html'
            },
            logout() {
                location.href = '/login.html'
            },
            search() {
                if (v.keyword.trim() === '') {
                    v.$message({
                        message: '搜索内容不能为空！',
                        type: 'warning'
                    });
                    return;
                }
                location.href = '/user/search.html?keyword=' + v.keyword;
            }
        },
        created: function () {
            axios.get('/carousel/list')
                .then(function (response) {
                    v.carousel = response.data.data;
                });
            axios.get('/banner/ListByEnable')
                .then(function (response) {
                    console.log(response.data.data);
                    v.bannerArr = response.data.data;
                });
            axios.get('/goods/list')
                .then(function (response) {
                    console.log("数据为: " + response.data.data);
                    v.goodsArr = response.data.data;
                });
            axios.get('/goods/sales')
                .then(function (response) {
                    v.sales = response.data.data;
                });
        }
    })
</script>
</html>